//
// Created by xili on 2024/8/8 10:54.
// Go big or go home.
//
#include <vector>
#include <algorithm>

using namespace std;

class Solution {
public:
    int maximumPopulation(vector<vector<int>> &logs) {
        //差分数组
        vector<int> cnt(101, 0);
        for (auto &item: logs) {
            cnt[item[0] - 1950]++;
            cnt[item[1] - 1950]--;
        }
        //还原数组
        int mx = -1;
        int index = -1;
        for (int i = 1; i < 101; i++) {
            cnt[i] += cnt[i - 1];
            if (cnt[i] > mx) {
                mx = cnt[i];
                index = i;
            }
        }
        return cnt[0] == mx ? 1950 : index + 1950;
    }
};